home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: howland.reston.ans.net!torn!sq!msb
- From: msb@sq.com (Mark Brader)
- Subject: Re: What's wrong here?
- Message-ID: <1996Feb2.214358.10906@sq.com>
- Organization: SoftQuad Inc., Toronto, Canada
- References: <4eml5o$o6h@airdmhor.gen.nz> <310FB5FF.4BE6@microsports.com>
- Date: Fri, 2 Feb 1996 21:43:58 GMT
-
- > You may be able to clear everything up by changing lines 9-11 to:
- > a = (word) 1;
- > b = (word) 2;
- > c = (word) 3;
-
- Considering that the spurious warnings begin on line 12, this seems
- *rather* unlikely. If a workaround of this kind is to be applied,
- it would be to change line 12 from
-
- d = a | b | c;
- to
- d = (word) (a | b | c);
-
- Of course, even with the redundant cast in place, the type of the
- right-hand side of the = sign is *still* int here. What this line
- now specifies, assuming that "word" (typedef'ed unsigned short) is
- narrower than int, is:
-
- 1. Widen the values of a and b to int
- 2. "Or" those two values together, producing an int
- 3. Widen the value of c to int [this step may be done earlier]
- 4. "Or" the two values from steps 2 and 3 together, producing an int
- 5. Narrow this int to unsigned short
- 6. Widen this unsigned short to int
- 7. Narrow this int to unsigned short
- 8. Assign this unsigned short to d
- 9. Widen the unsigned short to int
- 10. Discard the int
-
- where step 5 is the cast, but its presence merely causes step 6 to be
- inserted before the automatic conversion of step 7. In practice, of
- course, steps 5-7 will be optimized down to a single conversion, so
- the cast will have exactly no effect.
-
- But a compiler that would issue a warning for a line as innocuous as
- this might well be looking for exactly this change.
- --
- Mark Brader | "One of the lessons of history is that nothing
- msb@sq.com | is often a good thing to do and always a clever
- SoftQuad Inc., Toronto | thing to say." -- Will Durant
-
- My text in this article is in the public domain.
-